<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 需要考虑函数、正则、日期、ES6新对象 -->
    <script type="text/javascript">
        const _completeDeepClone = (target, map = new Map()) => {
                if (target === null) return target
                if (typeof target !== 'object') return target
                let reg = /^(Function|RegExp|Date|Map|Set)$/i, 
                    constructor = target.constructor
                if (reg.test(constructor.name)) {
                    return new constructor(target)
                }
                if (map.get(target)) return map.get(target)
                map.set(target, true)
                let cloneObj = Array.isArray(target) ? [] : {}
                for (let prop in target) {
                    if (target.hasOwnProperty(prop)) {
                       cloneObj[prop] = _completeDeepClone(target[prop], map)
                    }
                }
                return cloneObj
        }

        const target = {
            field1: 1,
            field2: undefined,
            field3: 'ConardLi',
            field4: {
                child: 'child',
                child2: {
                    child2: 'child2'
                }
            },
            field5: [1, 2, 3],
            field6: new Date(),
            field7: new RegExp('/ConardLi/i'),
            field8: function() {
                console.log('field8')
            },
            field9: NaN,
            field10: Infinity
        }
        console.log(_completeDeepClone(target))
    </script>
</body>
</html>

